﻿using System.IO;
using Map;
using Map_Creator.MapInfo;

namespace Map_Creator.RedoUndo.Actions
{
    class AddTileSetAction : IAction
    {
        private int mapID;
        private string tileSetFilePath;
        private string name;
        private TileSet tileSet;
        private int tileSetID = 0;

        public AddTileSetAction(MapInfo.Map map, string tileSetFilePath)
        {
            mapID = map.ID;
            this.tileSetFilePath = tileSetFilePath;
            name = Path.GetFileNameWithoutExtension(tileSetFilePath);
        }

        public void Do()
        {
            var map = ((MapInfo.Map)BaseObject.Objects[mapID]);

            map.AddTileSet(tileSetFilePath,tileSetID);
            
            tileSet = (TileSet)map.TileSets.Find(set => set.Name == name);
            tileSetID = tileSet.ID;
        }

        public void Undo()
        {
            tileSet.Delete();
        }

        public string GetDescription()
        {
            return "Add The " + name + " TileSet";
        }

        public string GetName()
        {
            return "Add TileSet";
        }
    }
}
